package top.italks.safemodule;

import android.content.Context;
import android.content.pm.PackageManager;
import android.util.Log;

import java.security.cert.CertificateException;

import top.italks.safemodule.debug.ApkDebugUtils;

//安卓应用安全手段
public class AndroidSafe {
    public static final String TAG = "AndroidSafe";
    private static Context mContext;
    public static void init(Context context){
        mContext=context;
        Log.d(TAG,"NativeLib="+new NativeLib().stringFromJNI());
        showDecetion();
    }
    //输出检测结果
    public static void showDecetion(){
        simulator();
        debug();
        signIsRight();
    }
    static {
        System.loadLibrary("native-lib");
    }


    //***********以上是对外暴露的接口

    private static void simulator(){
        SimulatorUtils.readBuild();
    }
    private static void debug(){
        ApkDebugUtils apkDebugUtils=new ApkDebugUtils(mContext);
        apkDebugUtils.isDebugger();
        apkDebugUtils.apkIsDebugger();
        //如果进入调试模式则退出
        apkDebugUtils.checkDebuggableInNotDebugModel();
    }
    private static void signIsRight(){
        SignUtils signUtils=new SignUtils(mContext);
        try {
            Log.d(TAG,"签名是否一直:"+signUtils.getSingInfo(signUtils.getSignSHA256()));
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        } catch (CertificateException e) {
            e.printStackTrace();
        }
    }
}
